package model;

import java.util.ArrayList;
import java.util.List;
import java.lang.String;

import javax.swing.table.AbstractTableModel;

public class PackTableModel extends AbstractTableModel {
	private static final long serialVersionUID = 1549080676419132765L;
	private List<List<String>> list = new ArrayList<List<String>>();
	private String[] colunmname = { "序号", "协议", "源地址", "目的地址", "信息" };
	private static int MinRow = 14;

	@Override
	public int getRowCount() {
		if (list.size() > MinRow)
			return list.size();
		else
			return MinRow;
	}

	@Override
	public int getColumnCount() {
		return colunmname.length;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		if (rowIndex < list.size()) {
			if (columnIndex == 0)
				return rowIndex + 1;
			if (columnIndex < list.size()) {
				if (rowIndex < list.size() && columnIndex - 1 < list.get(rowIndex).size())
					return list.get(rowIndex).get(columnIndex - 1);
			}
		}
		return "";
	}

	public String getColumnName(int column) {
		return colunmname[column];
	}

	public void add(List<String> pt) {
		list.add(pt);
		fireTableDataChanged();
	}

	public void clear() {
		list = new ArrayList<List<String>>();
		fireTableDataChanged();
	}
}
